package com.future.hedongjun.mine.order;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.baselib.activity.BaseListFragment;
import com.future.hedongjun.mall.bean.OrderDetail;
import com.future.hedongjun.mine.adapter.OrderAdapter;
import com.future.hedongjun.mine.bean.DeliveryAddressBean;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * A simple {@link Fragment} subclass.
 */
public class OrderListFragment extends BaseListFragment {

    public static final int TYPE_ALL = 0x111;
    public static final int TYPE_CLASS_ALL = 0x112;
    public static final int TYPE_WAIT_PAY = 0;
    public static final int TYPE_WAIT_SEND = 1;
    public static final int TYPE_WAIT_GET = 2;
    public static final int TYPE_TUIKUAN_ING = 6;
    private int type;
    //0商城全部 1 代付款 2 待发货 3待收货 4 退款审核中 5课程全部

    public OrderListFragment() {
        // Required empty public constructor
    }

    public static OrderListFragment getInstance(int type) {
        OrderListFragment fragment = new OrderListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    protected void getBundleExtras(Bundle extras) {
        type = extras.getInt("type");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        return view;
    }

    @Override
    protected void initView(View view, @Nullable Bundle savedInstanceState) {

    }

    @Override
    protected BaseQuickAdapter getAdapter() {
        return new OrderAdapter(initTestData());
    }

    private List<OrderDetail> initTestData() {
        List<OrderDetail> data = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            OrderDetail detail = new OrderDetail();
            detail.id = "" + (i + 1);
            detail.couponPrice = 5;
            detail.orderNum = "123456789";
            detail.status = i;
            detail.addressBean = new DeliveryAddressBean();
//            detail.addressBean.setUsername("小猪猪");
//            detail.addressBean.setPhone("13333333333");
//            detail.addressBean.setProvince("浙江省");
//            detail.addressBean.setCity("杭州市");
//            detail.addressBean.setArea("滨江区");
//            detail.addressBean.setArea("星光大道100幢110号");
            detail.addressBean.setAddress_id("10");
            detail.amount = 100;
            detail.goodsBeanList = new ArrayList<>();
            OrderDetail.GoodsBean bean = new OrderDetail.GoodsBean();
            bean.sku = "商品属性";
            bean.title = "商品名称";
            bean.imgUrl = "http://seopic.699pic.com/photo/50025/2423.jpg_wh1200.jpg";
            bean.count = 1;
            bean.price = 30;
            detail.goodsBeanList.add(bean);
            OrderDetail.GoodsBean bean1 = new OrderDetail.GoodsBean();
            bean1.sku = "商品属性";
            bean1.title = "商品名称";
            bean1.imgUrl = "http://seopic.699pic.com/photo/50025/2423.jpg_wh1200.jpg";
            bean1.count = 2;
            bean1.price = 40;
            detail.goodsBeanList.add(bean1);
            data.add(detail);
        }
        return data;
    }

    @Override
    protected Type getTypeToken() {
        return null;
    }

    @Override
    protected TreeMap<String, String> getRequestParams() {
        return new TreeMap<>();
    }

    @Override
    protected String getPath() {
        return null;
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("order_num", ((OrderAdapter) adapter).getData().get(position).orderNum);
        startActivity(OrderDetailActivity.class, bundle);
    }
}
